package com.piesat.quake.business.device.model;

import com.piesat.quake.business.device.model.config.NtpData;
import com.piesat.quake.business.device.model.config.Passageway;
import com.piesat.quake.business.device.model.config.StationData;
import com.piesat.quake.business.device.model.config.ThresholdData;
import com.piesat.quake.business.device.mqtt.anno.CharField;
import com.piesat.quake.business.device.mqtt.anno.IgnoreField;
import com.piesat.quake.business.device.mqtt.anno.LengthField;
import com.piesat.quake.business.device.mqtt.anno.NodeField;

import java.util.List;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 更新地震仪配置
 * 设备下行 QoS1
 *
 * @author Gersy
 * @date 2023/2/14
 * @since 1.0
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class ConfigurationUpdate extends BaseModel {
    public static final short NETWORK = 1;
    public static final short STATION_INFO = 2;
    public static final short THRESHOLD = 3;
    public static final short PASSAGEWAY = 4;
    public static final short NTP = 5;
    //子配置命令	Short	2B	1  网络配置 2  台站信息 3  事件检测模式与阈值调整 4  通道配置调整 5  NTP配置
    private short configType;
    //子配置对应数据块		nB	不同子配置对应的数据块，其大小不一致；
    @IgnoreField
//    @NodeField
    private Network network;

    @NodeField
    private StationData stationData;
    @NodeField
    private ThresholdData threshold;
    @IgnoreField
    private PassagewayConfig passageway;
    @IgnoreField
    private NtpData ntp;

    @IgnoreField
    private Integer targetType;

    public ConfigurationUpdate() {
        super("cs");
    }

    /**
     * 网络配置
     */
    @Data
    public static class Network {
        public static final byte MQTT = 1;
        public static final byte FTP = 2;
        public static final byte FTP_LOG = 3;
        public static final byte UPDATE = 4;
        //数据块长度	Int	4B	对于 1 网络配置的数据块，整个数据块的长度；
        @LengthField
        private int length;
        //通信形式	Byte	1B	1  MQTT 2  FTP 3  日志传输 4  软件更新仓库
        private byte communicationType;

        @IgnoreField
        private NetworkData mqttConfig;
        @IgnoreField
        private NetworkData ftpConfig;
        @IgnoreField
        private NetworkData ftpLogConfig;
        @IgnoreField
        private NetworkData updateConfig;

    }

    /**
     * 台站信息
     */
    public static class StationInfo {
        //数据块长度	Int	4B	对于 2 台站信息的数据块，整个数据块的长度；
        @LengthField
        private int length;
        //最新台站ID	Char	8B	格式为：xx.xxxxx（台网代码.台站代码），编码规则见地震行业的《地震数据通道编码》标准。该台站ID为最新的台站ID，即若服务器端需修改设备台站ID，则改动该项。
        @CharField(8)
        private String id;
        //经度	Float	4B	地震仪安装位置经度，范围0-180°；
        private float longitude;
        //纬度	Float	4B	地震仪安装位置纬度，范围0-90°；
        private float latitude;
        //安装方位	Float	4B	地震仪安装时的方位角，为地震仪X轴正向与正东方向的夹角，范围0-360°；
        private float azimuthal;
        //应变阈值	Float	4B	应变阈值；
        private float strainThreshold;
        //加速度阈值	Float	4B	加速度阈值；
        private float accelerationThreshold;
        //台网编号	Char	2B	台网代码，例如GD表示广东；
        @CharField(2)
        private String code;
        //位置标识符	Char	2B	台站的地震计编号；
        @CharField(2)
        private String number;
        //实时上传点数	Int	4B	实时数据报文每个通道每次上传的数据点数；
        private int passageDataCount;
        //采样点数	Int	4B	传感器每个通道的数据采样率
        private int samplingRate;
        //振动模式	Byte	1B	0表示3振动模式； 1表示6振动模式； 2表示9振动模式。
        private byte mode;
        //版本	Char	8B	设备软件版本标识；例如：03.00.01；
        @CharField(8)
        private String version;
    }



    /**
     * 通道配置调整
     */
    public static class PassagewayConfig {
        //数据块长度	Int	4B	对于 4 通道配置调整的数据块，整个数据块的长度；
        @LengthField
        private int length;

        @IgnoreField
        private List<Passageway> passageways;

        @NodeField(clazz = Passageway.class)
        Passageway passageway1;
        @NodeField(clazz = Passageway.class)
        Passageway passageway2;
        @NodeField(clazz = Passageway.class)
        Passageway passageway3;
        @NodeField(clazz = Passageway.class)
        Passageway passageway4;
        @NodeField(clazz = Passageway.class)
        Passageway passageway5;
        @NodeField(clazz = Passageway.class)
        Passageway passageway6;

        public int getLength() {
            return length;
        }

        public void setLength(int length) {
            this.length = length;
        }

        public List<Passageway> getPassageways() {
            return passageways;
        }

        public void setPassageways(List<Passageway> passageways) {
            this.passageways = passageways;
            passageway1=passageways.get(0);
            passageway2=passageways.get(1);
            passageway3=passageways.get(2);
            passageway4=passageways.get(3);
            passageway5=passageways.get(4);
            passageway6=passageways.get(5);
        }

        public Passageway getPassageway1() {
            return passageway1;
        }

        public void setPassageway1(Passageway passageway1) {
            this.passageway1 = passageway1;
        }

        public Passageway getPassageway2() {
            return passageway2;
        }

        public void setPassageway2(Passageway passageway2) {
            this.passageway2 = passageway2;
        }

        public Passageway getPassageway3() {
            return passageway3;
        }

        public void setPassageway3(Passageway passageway3) {
            this.passageway3 = passageway3;
        }

        public Passageway getPassageway4() {
            return passageway4;
        }

        public void setPassageway4(Passageway passageway4) {
            this.passageway4 = passageway4;
        }

        public Passageway getPassageway5() {
            return passageway5;
        }

        public void setPassageway5(Passageway passageway5) {
            this.passageway5 = passageway5;
        }

        public Passageway getPassageway6() {
            return passageway6;
        }

        public void setPassageway6(Passageway passageway6) {
            this.passageway6 = passageway6;
        }
    }
}
